package com.zzyl.controller.customer;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.ReservationDto;
import com.zzyl.service.CostomerReservationService;
import com.zzyl.vo.ReservationVo;
import com.zzyl.vo.TimeCountVo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/customer/reservation")
public class CostomerReservationController extends BaseController {
   @Autowired
    private CostomerReservationService costomerReservationService;

   @GetMapping("/cancelled-count")
   @ApiOperation("查询取消预约的数量")
    public ResponseResult costomerReservationCount(){
       Integer count=costomerReservationService.countReservation();
        return success(count);
    }
@GetMapping("/countByTime")
@ApiOperation("查询每个时间段剩余预约的次数")
     public ResponseResult cotomerReservationCountByTime( Long time){
       List<TimeCountVo> list=costomerReservationService.cotomerReservationCountByTime(LocalDateTimeUtil.of(time));
       return success(list);

     }
     @PostMapping
     @ApiOperation("新增预约")
     public ResponseResult add(@RequestBody ReservationDto reservationDto){
      costomerReservationService.add(reservationDto);
      return success();
     }
     //分页查询预约
    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    public  ResponseResult<PageResponse<ReservationVo>>findByPage(Integer pageNum,Integer pageSize,Integer status ){
       PageResponse<ReservationVo> pageResponse=costomerReservationService.getByPage(pageNum,pageSize,status);
       return success(pageResponse);

    }
    //取消预约
    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public ResponseResult cancel(@PathVariable Long id){
       costomerReservationService.cancel(id);
       return null;
    }
}
